<?php

/**
 *
 * @author nhan
 *
 */
class Model_Product extends Model_AbstractModel{
	private $name;
	private $price;
	private $oldPrice;
	private $detail;
	private $imageUrl;
	private $viewTimes;
	private $idProductClass;
	private $idCategory;
	private $origin;
	private $yearOfManufacture;
	private $capacity;
	private $level;
	private $specialRange;

	// column of productclass table
	private $nameClass;
	private $nameClassFolder;

	// column of category
	private $nameCategory;

	public function __construct($data) {
		parent::__construct($data);
		if (is_array($data)) {

			if (isset($data['name'])) {
				$this->name = $data['name'];
			}

			if (isset($data['price'])) {
				$this->price = $data['price'];
			}

			if (isset($data['old_price'])) {
				$this->oldPrice = $data['old_price'];
			}

			if (isset($data['detail'])) {
				$this->detail = $data['detail'];
			}

			if (isset($data['image_url'])) {
				$this->imageUrl = $data['image_url'];
			}

			if (isset($data['view_time'])) {
				$this->viewTimes = $data['view_time'];
			}

			if (isset($data['id_product_class'])) {
				$this->idProductClass = $data['id_product_class'];
			}

			if (isset($data['id_category'])) {
				$this->idCategory = $data['id_category'];
			}

			if (isset($data['name_class'])) {
				$this->nameClass = $data['name_class'];
			}

			if (isset ( $data ['name_class_folder'] )) {
				$this->nameClassFolder = $data ['name_class_folder'];
			}

			if (isset ( $data ['origin'] )) {
				$this->origin = $data ['origin'];
			}

			if (isset ( $data ['year_of_manufacture'] )) {
				$this->yearOfManufacture = $data ['year_of_manufacture'];
			}

			if (isset ( $data ['capacity'] )) {
				$this->capacity = $data ['capacity'];
			}

			if (isset ( $data ['level'] )) {
				$this->level = $data ['level'];
			}

			if (isset($data['category_name'])) {
				$this->nameCategory = $data['category_name'];
			}

			if (isset ( $data ['special_range'] )) {
				$this->specialRange = $data ['special_range'];
			}

		}
	}

	/**
	 * (non-PHPdoc)
	 * @see Model_AbstractModel::toArray()
	 */
	public function toArray() {
		$arr = parent::toArray();
		$arr['name'] 				= $this->name;
		$arr['id_product_class'] 	= $this->idProductClass;
		$arr['id_category'] 		= $this->idCategory;
		$arr['origin'] 				= $this->origin;
		$arr['year_of_manufacture'] = $this->yearOfManufacture;
		$arr['capacity'] 			= $this->capacity;
		$arr['level'] 				= $this->level;
		$arr['price'] 				= $this->price;
		$arr['detail'] 				= $this->detail;
		$arr['view_time'] 			= $this->viewTimes;
		$arr['old_price'] 			= $this->oldPrice;
		$arr['image_url'] 			= $this->imageUrl;
		//$arr['name_class'] 			= $this->nameClass;
		//$arr['name_class_folder'] 	= $this->nameClassFolder;

		return $arr;
	}

	// Get Data
	public function getName() {
		return $this->name;
	}
	public function getDetail() {
		return $this->detail;
	}
	public function getImageUrl() {
		return $this->imageUrl;
	}
	public function getViewTimes() {
		return $this->viewTimes;
	}
	public function getIdCategory() {
		return $this->idCategory;
	}
	public function getIdProductClass() {
		return $this->idProductClass;
	}
	public function getPrice() {
		return $this->price;
	}
	public function getOldPrice() {
		return $this->oldPrice;
	}
	public function getNameClass() {
		return $this->nameClass;
	}

	public function getNameClassFolder() {
		//return $this->nameClassFolder;
		return $this->idProductClass;
	}

	public function getOrigin() {
		return $this->origin;
	}

	public function getYearOfManufacture() {
		return $this->yearOfManufacture;
	}

	public function getCapacity() {
		return $this->capacity;
	}

	public function getLevel() {
		return $this->level;
	}

	public function getSpecialRange() {
		return $this->specialRange;
	}


	// Set Data
	public function setName($name) {
		$this->name = $name;
	}
	public function setDetail($x) {
		$this->detail = $x;
	}
	public function setIdProductClass($x) {
		$this->idProductClass = $x;
	}
	public function setImageUrl($x) {
		$this->imageUrl = $x;
	}
	public function setViewTimes($x) {
		$this->viewTimes = $x;
	}
	public function setIdCategory($x) {
		$this->idCategory = $x;
	}
	public function setPrice($price) {
		$this->price = $price;
	}
	public function setOldPrice($oldPrice) {
		$this->oldPrice = $oldPrice;
	}
	public function setNameClass($nameClass) {
		$this->nameClass = $nameClass;
	}

	public function setNameClassFolder($x) {
		$this->nameClassFolder = $x;
	}

	public function setOrigin($x) {
		$this->origin = $x;
	}

	public function setYearOfManufacture($x) {
		$this->yearOfManufacture = $x;
	}

	public function setCapacity($x) {
		$this->capacity = $x;
	}

	public function setLevel($x) {
		$this->level = $x;
	}

	public function getNameCategory() {
		return $this->nameCategory;
	}

	public function setSpecialRange($x) {
		$this->specialRange = $x;
	}

	public function getFullImagePath() {
		if ($this->getImageUrl() !== null && trim($this->getImageUrl()) !== '') {
			return PICTURE_PROD_FOLDER . "/" . $this->getNameClassFolder(). "/" . $this->getImageUrl();
		} else {
			return PICTURE_PROD_FOLDER . "/" . common_commonConst::NO_IMAGE_VAR ;
		}
	}

}